/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Algorithm;

import StrategyCompare.Sort;
import pkg0912144.pkg0912207.array.HKBox;

/**
 *
 * @author khangdc
 */
public class NomalSort<E> extends Algorithm<E> {

    @Override
    public void sort(HKBox<E> list, Sort strategy, comparetor.Comparetor<E> compare) {
        int size = list.getSize();
        for (int i = 0; i <size - 1; i++) {
            for (int j = i + 1; j < size; j++) {
                E obj1 = list.get(i);
                E obj2 = list.get(j);
                boolean bool = strategy.sortStr(obj1, obj2, compare);
                if(bool)
                {
                    //Swap
                    E tmp = obj1;
                    obj1 = obj2;
                    obj2 = tmp;
                    //Set value for array
                    list.set(i, obj1);
                    list.set(j, obj2);
                }
            }
        }
    }
}
